/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * V3PersCrearNuevo.java
 *
 * Created on 14-may-2012, 12:48:57
 */
package practtica4;

import BBDD.GestorBBDD;
import MetodosAuxiliares.MetAux;
import java.sql.Date;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author usuario_local
 */
public class V3PersCrearNuevo extends javax.swing.JFrame {

    GestorBBDD gestor= new GestorBBDD();
    MetAux metAux= new MetAux();
    int iddoc;
    /** Creates new form V3PersCrearNuevo */
    public V3PersCrearNuevo() {
        initComponents();
    }

    V3PersCrearNuevo(int iddoc) throws ClassNotFoundException, SQLException {
        this.iddoc=iddoc;

        initComponents();
        botonId.setText(Integer.toString(gestor.numPers()));
        botonId.setEnabled(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botonLugMuerte = new javax.swing.JTextField();
        labelId = new javax.swing.JLabel();
        labelFechaNac = new javax.swing.JLabel();
        labelFechaMuerte = new javax.swing.JLabel();
        botonBio = new javax.swing.JTextField();
        labelBio = new javax.swing.JLabel();
        labelApellido = new javax.swing.JLabel();
        botonApellido = new javax.swing.JTextField();
        labelNombre = new javax.swing.JLabel();
        botonFechaNac = new javax.swing.JTextField();
        botonId = new javax.swing.JTextField();
        botonLugNac = new javax.swing.JTextField();
        botonNombre = new javax.swing.JTextField();
        labelLugMuerte = new javax.swing.JLabel();
        botonFechaMuerte = new javax.swing.JTextField();
        labelLugNac = new javax.swing.JLabel();
        botonAceptar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        labelId.setText("id");

        labelFechaNac.setText("Fecha nacimiento");

        labelFechaMuerte.setText("Fecha muerte");

        labelBio.setText("Biografía");

        labelApellido.setText("apellido");

        botonApellido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonApellidoActionPerformed(evt);
            }
        });

        labelNombre.setText("nombre");

        botonFechaNac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonFechaNacActionPerformed(evt);
            }
        });

        labelLugMuerte.setText("Lugar muerte");

        labelLugNac.setText("Lugar nacimiento");

        botonAceptar.setText("Aceptar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        jLabel1.setText("YYYY/MM/DD");

        jLabel2.setText("YYYY/MM/DD");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelLugMuerte)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(labelLugNac)
                            .addContainerGap())
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(labelId)
                                .addGap(154, 154, 154)
                                .addComponent(botonId, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                                .addComponent(botonAceptar))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelFechaNac)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(labelBio)
                                        .addComponent(labelApellido))
                                    .addComponent(labelFechaMuerte)
                                    .addComponent(labelNombre))
                                .addGap(79, 79, 79)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(botonBio)
                                            .addComponent(botonFechaNac)
                                            .addComponent(botonApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel1))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(botonNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                        .addGap(65, 65, 65))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(botonFechaMuerte, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(botonLugMuerte, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(botonLugNac, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                                        .addComponent(jLabel2)))
                                .addContainerGap())))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelId)
                    .addComponent(botonId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNombre)
                    .addComponent(botonNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelApellido)
                    .addComponent(botonApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelBio)
                    .addComponent(botonBio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelFechaNac)
                    .addComponent(botonFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelFechaMuerte)
                    .addComponent(botonFechaMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelLugNac)
                    .addComponent(botonLugNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelLugMuerte)
                    .addComponent(botonLugMuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonAceptar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void botonApellidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonApellidoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_botonApellidoActionPerformed

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        // TODO add your handling code here:
        String id=botonId.getText();
        if(id.isEmpty()||!metAux.isNumeric(id)){
            JOptionPane.showMessageDialog(this, "Rellenar campo id, sólo con números");
        }
        int id2=Integer.parseInt(id);
        String nombre=botonNombre.getText();
        if(nombre.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Nombre");
        String apellido=botonApellido.getText();
        if(apellido.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Apellido");
        String biografia=botonBio.getText();
        if(biografia.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Biografia");
        String fechanacimiento=botonFechaNac.getText();
        if(fechanacimiento.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Fecha nacimiento");
        String fechamuerte=botonFechaMuerte.getText();
        if(fechamuerte.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Fecha muerte");

        String lugarnacimiento=botonLugNac.getText();

        if(lugarnacimiento.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Lugar nacimiento");
        String lugarmuerte=botonLugMuerte.getText();
        if(lugarmuerte.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Lugar muerte");

        try {
            gestor.anyadirDocTienePers(iddoc,id2);
            gestor.anyadirPersonaje(id2,nombre,apellido,biografia,fechanacimiento,fechamuerte,lugarnacimiento,lugarmuerte);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(V3PersCrearNuevo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(V3PersCrearNuevo.class.getName()).log(Level.SEVERE, null, ex);
        }
        V3 v3=new V3(iddoc);
        v3.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_botonAceptarActionPerformed

private void botonFechaNacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonFechaNacActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_botonFechaNacActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(V3PersCrearNuevo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(V3PersCrearNuevo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(V3PersCrearNuevo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(V3PersCrearNuevo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new V3PersCrearNuevo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JTextField botonApellido;
    private javax.swing.JTextField botonBio;
    private javax.swing.JTextField botonFechaMuerte;
    private javax.swing.JTextField botonFechaNac;
    private javax.swing.JTextField botonId;
    private javax.swing.JTextField botonLugMuerte;
    private javax.swing.JTextField botonLugNac;
    private javax.swing.JTextField botonNombre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel labelApellido;
    private javax.swing.JLabel labelBio;
    private javax.swing.JLabel labelFechaMuerte;
    private javax.swing.JLabel labelFechaNac;
    private javax.swing.JLabel labelId;
    private javax.swing.JLabel labelLugMuerte;
    private javax.swing.JLabel labelLugNac;
    private javax.swing.JLabel labelNombre;
    // End of variables declaration//GEN-END:variables
}
